/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.open.oasis.docs.wsbpel._2._0.process.abstract_.impl;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.open.oasis.docs.wsbpel._2._0.process.abstract_.AbstractPackage;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TBoolean;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TCompletionCondition;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TExpression;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TForEach;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.TScope;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>TFor Each</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.open.oasis.docs.wsbpel._2._0.process.abstract_.impl.TForEachImpl#getStartCounterValue <em>Start Counter Value</em>}</li>
 *   <li>{@link org.open.oasis.docs.wsbpel._2._0.process.abstract_.impl.TForEachImpl#getFinalCounterValue <em>Final Counter Value</em>}</li>
 *   <li>{@link org.open.oasis.docs.wsbpel._2._0.process.abstract_.impl.TForEachImpl#getCompletionCondition <em>Completion Condition</em>}</li>
 *   <li>{@link org.open.oasis.docs.wsbpel._2._0.process.abstract_.impl.TForEachImpl#getScope <em>Scope</em>}</li>
 *   <li>{@link org.open.oasis.docs.wsbpel._2._0.process.abstract_.impl.TForEachImpl#getCounterName <em>Counter Name</em>}</li>
 *   <li>{@link org.open.oasis.docs.wsbpel._2._0.process.abstract_.impl.TForEachImpl#getParallel <em>Parallel</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class TForEachImpl extends TActivityImpl implements TForEach {
	/**
	 * The cached value of the '{@link #getStartCounterValue() <em>Start Counter Value</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStartCounterValue()
	 * @generated
	 * @ordered
	 */
	protected TExpression startCounterValue;

	/**
	 * The cached value of the '{@link #getFinalCounterValue() <em>Final Counter Value</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFinalCounterValue()
	 * @generated
	 * @ordered
	 */
	protected TExpression finalCounterValue;

	/**
	 * The cached value of the '{@link #getCompletionCondition() <em>Completion Condition</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCompletionCondition()
	 * @generated
	 * @ordered
	 */
	protected TCompletionCondition completionCondition;

	/**
	 * The cached value of the '{@link #getScope() <em>Scope</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getScope()
	 * @generated
	 * @ordered
	 */
	protected TScope scope;

	/**
	 * The default value of the '{@link #getCounterName() <em>Counter Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCounterName()
	 * @generated
	 * @ordered
	 */
	protected static final Object COUNTER_NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getCounterName() <em>Counter Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCounterName()
	 * @generated
	 * @ordered
	 */
	protected Object counterName = COUNTER_NAME_EDEFAULT;

	/**
	 * The default value of the '{@link #getParallel() <em>Parallel</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getParallel()
	 * @generated
	 * @ordered
	 */
	protected static final TBoolean PARALLEL_EDEFAULT = TBoolean.YES;

	/**
	 * The cached value of the '{@link #getParallel() <em>Parallel</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getParallel()
	 * @generated
	 * @ordered
	 */
	protected TBoolean parallel = PARALLEL_EDEFAULT;

	/**
	 * This is true if the Parallel attribute has been set.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 * @ordered
	 */
	protected boolean parallelESet;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected TForEachImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return AbstractPackage.eINSTANCE.getTForEach();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public TExpression getStartCounterValue() {
		return startCounterValue;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetStartCounterValue(TExpression newStartCounterValue, NotificationChain msgs) {
		TExpression oldStartCounterValue = startCounterValue;
		startCounterValue = newStartCounterValue;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, AbstractPackage.TFOR_EACH__START_COUNTER_VALUE, oldStartCounterValue, newStartCounterValue);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setStartCounterValue(TExpression newStartCounterValue) {
		if (newStartCounterValue != startCounterValue) {
			NotificationChain msgs = null;
			if (startCounterValue != null)
				msgs = ((InternalEObject)startCounterValue).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - AbstractPackage.TFOR_EACH__START_COUNTER_VALUE, null, msgs);
			if (newStartCounterValue != null)
				msgs = ((InternalEObject)newStartCounterValue).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - AbstractPackage.TFOR_EACH__START_COUNTER_VALUE, null, msgs);
			msgs = basicSetStartCounterValue(newStartCounterValue, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, AbstractPackage.TFOR_EACH__START_COUNTER_VALUE, newStartCounterValue, newStartCounterValue));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public TExpression getFinalCounterValue() {
		return finalCounterValue;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetFinalCounterValue(TExpression newFinalCounterValue, NotificationChain msgs) {
		TExpression oldFinalCounterValue = finalCounterValue;
		finalCounterValue = newFinalCounterValue;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, AbstractPackage.TFOR_EACH__FINAL_COUNTER_VALUE, oldFinalCounterValue, newFinalCounterValue);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setFinalCounterValue(TExpression newFinalCounterValue) {
		if (newFinalCounterValue != finalCounterValue) {
			NotificationChain msgs = null;
			if (finalCounterValue != null)
				msgs = ((InternalEObject)finalCounterValue).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - AbstractPackage.TFOR_EACH__FINAL_COUNTER_VALUE, null, msgs);
			if (newFinalCounterValue != null)
				msgs = ((InternalEObject)newFinalCounterValue).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - AbstractPackage.TFOR_EACH__FINAL_COUNTER_VALUE, null, msgs);
			msgs = basicSetFinalCounterValue(newFinalCounterValue, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, AbstractPackage.TFOR_EACH__FINAL_COUNTER_VALUE, newFinalCounterValue, newFinalCounterValue));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public TCompletionCondition getCompletionCondition() {
		return completionCondition;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetCompletionCondition(TCompletionCondition newCompletionCondition, NotificationChain msgs) {
		TCompletionCondition oldCompletionCondition = completionCondition;
		completionCondition = newCompletionCondition;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, AbstractPackage.TFOR_EACH__COMPLETION_CONDITION, oldCompletionCondition, newCompletionCondition);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCompletionCondition(TCompletionCondition newCompletionCondition) {
		if (newCompletionCondition != completionCondition) {
			NotificationChain msgs = null;
			if (completionCondition != null)
				msgs = ((InternalEObject)completionCondition).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - AbstractPackage.TFOR_EACH__COMPLETION_CONDITION, null, msgs);
			if (newCompletionCondition != null)
				msgs = ((InternalEObject)newCompletionCondition).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - AbstractPackage.TFOR_EACH__COMPLETION_CONDITION, null, msgs);
			msgs = basicSetCompletionCondition(newCompletionCondition, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, AbstractPackage.TFOR_EACH__COMPLETION_CONDITION, newCompletionCondition, newCompletionCondition));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public TScope getScope() {
		return scope;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetScope(TScope newScope, NotificationChain msgs) {
		TScope oldScope = scope;
		scope = newScope;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, AbstractPackage.TFOR_EACH__SCOPE, oldScope, newScope);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setScope(TScope newScope) {
		if (newScope != scope) {
			NotificationChain msgs = null;
			if (scope != null)
				msgs = ((InternalEObject)scope).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - AbstractPackage.TFOR_EACH__SCOPE, null, msgs);
			if (newScope != null)
				msgs = ((InternalEObject)newScope).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - AbstractPackage.TFOR_EACH__SCOPE, null, msgs);
			msgs = basicSetScope(newScope, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, AbstractPackage.TFOR_EACH__SCOPE, newScope, newScope));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Object getCounterName() {
		return counterName;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCounterName(Object newCounterName) {
		Object oldCounterName = counterName;
		counterName = newCounterName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, AbstractPackage.TFOR_EACH__COUNTER_NAME, oldCounterName, counterName));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public TBoolean getParallel() {
		return parallel;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setParallel(TBoolean newParallel) {
		TBoolean oldParallel = parallel;
		parallel = newParallel == null ? PARALLEL_EDEFAULT : newParallel;
		boolean oldParallelESet = parallelESet;
		parallelESet = true;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, AbstractPackage.TFOR_EACH__PARALLEL, oldParallel, parallel, !oldParallelESet));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void unsetParallel() {
		TBoolean oldParallel = parallel;
		boolean oldParallelESet = parallelESet;
		parallel = PARALLEL_EDEFAULT;
		parallelESet = false;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.UNSET, AbstractPackage.TFOR_EACH__PARALLEL, oldParallel, PARALLEL_EDEFAULT, oldParallelESet));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isSetParallel() {
		return parallelESet;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case AbstractPackage.TFOR_EACH__START_COUNTER_VALUE:
				return basicSetStartCounterValue(null, msgs);
			case AbstractPackage.TFOR_EACH__FINAL_COUNTER_VALUE:
				return basicSetFinalCounterValue(null, msgs);
			case AbstractPackage.TFOR_EACH__COMPLETION_CONDITION:
				return basicSetCompletionCondition(null, msgs);
			case AbstractPackage.TFOR_EACH__SCOPE:
				return basicSetScope(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case AbstractPackage.TFOR_EACH__START_COUNTER_VALUE:
				return getStartCounterValue();
			case AbstractPackage.TFOR_EACH__FINAL_COUNTER_VALUE:
				return getFinalCounterValue();
			case AbstractPackage.TFOR_EACH__COMPLETION_CONDITION:
				return getCompletionCondition();
			case AbstractPackage.TFOR_EACH__SCOPE:
				return getScope();
			case AbstractPackage.TFOR_EACH__COUNTER_NAME:
				return getCounterName();
			case AbstractPackage.TFOR_EACH__PARALLEL:
				return getParallel();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case AbstractPackage.TFOR_EACH__START_COUNTER_VALUE:
				setStartCounterValue((TExpression)newValue);
				return;
			case AbstractPackage.TFOR_EACH__FINAL_COUNTER_VALUE:
				setFinalCounterValue((TExpression)newValue);
				return;
			case AbstractPackage.TFOR_EACH__COMPLETION_CONDITION:
				setCompletionCondition((TCompletionCondition)newValue);
				return;
			case AbstractPackage.TFOR_EACH__SCOPE:
				setScope((TScope)newValue);
				return;
			case AbstractPackage.TFOR_EACH__COUNTER_NAME:
				setCounterName(newValue);
				return;
			case AbstractPackage.TFOR_EACH__PARALLEL:
				setParallel((TBoolean)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case AbstractPackage.TFOR_EACH__START_COUNTER_VALUE:
				setStartCounterValue((TExpression)null);
				return;
			case AbstractPackage.TFOR_EACH__FINAL_COUNTER_VALUE:
				setFinalCounterValue((TExpression)null);
				return;
			case AbstractPackage.TFOR_EACH__COMPLETION_CONDITION:
				setCompletionCondition((TCompletionCondition)null);
				return;
			case AbstractPackage.TFOR_EACH__SCOPE:
				setScope((TScope)null);
				return;
			case AbstractPackage.TFOR_EACH__COUNTER_NAME:
				setCounterName(COUNTER_NAME_EDEFAULT);
				return;
			case AbstractPackage.TFOR_EACH__PARALLEL:
				unsetParallel();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case AbstractPackage.TFOR_EACH__START_COUNTER_VALUE:
				return startCounterValue != null;
			case AbstractPackage.TFOR_EACH__FINAL_COUNTER_VALUE:
				return finalCounterValue != null;
			case AbstractPackage.TFOR_EACH__COMPLETION_CONDITION:
				return completionCondition != null;
			case AbstractPackage.TFOR_EACH__SCOPE:
				return scope != null;
			case AbstractPackage.TFOR_EACH__COUNTER_NAME:
				return COUNTER_NAME_EDEFAULT == null ? counterName != null : !COUNTER_NAME_EDEFAULT.equals(counterName);
			case AbstractPackage.TFOR_EACH__PARALLEL:
				return isSetParallel();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (counterName: ");
		result.append(counterName);
		result.append(", parallel: ");
		if (parallelESet) result.append(parallel); else result.append("<unset>");
		result.append(')');
		return result.toString();
	}

} //TForEachImpl
